package experiment_sixth;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.EOFException;

public class TestXuanke {
	
	@SuppressWarnings("resource")
	public static void main(String[] args) throws EOFException,FileNotFoundException, IOException, ClassNotFoundException {
	    Course course = new Course(); 
		System.out.println(course.toString());

		Student stu0 = new Student(2020310356,"刘天皓   ","男   ","汉族","计算机");
        Student stu1 = new Student(2020310357,"张一   ","男   ","回族","大数据");
        Student stu2 = new Student(2020310358,"张二   ","女   ","满族","物联网");
        Student stu3 = new Student(2020310359,"张三","男","汉族","计算机");
        Teacher tea0 = new Teacher(2000000000,"余老师   ","性别：男   ");
        Teacher tea1 = new Teacher(2000000001,"庄老师   ","性别：男   ");
        Teacher tea2 = new Teacher(2000000002,"张老师   ","性别：男   ");
        Course cour0 = new Course(101,"Linux ","综0901   ","周一   9:30分");
        Course cour1 = new Course(102," 线性代数  ","教302   ","周二  13:30");
        Course cour2 = new Course(103,"java ","综0901   ","周三  8:00");
        stu0.addCourse(cour0);
        stu0.addCourse(cour1);
        stu0.addCourse(cour2);
        stu1.addCourse(cour0);
        stu1.addCourse(cour1);
        stu1.addCourse(cour2);
        stu2.addCourse(cour1);
        stu3.addCourse(cour0);
        stu3.addCourse(cour2);
        tea0.addCourse(cour0);
        tea1.addCourse(cour1);
        tea2.addCourse(cour2); 
               
        stu0.removeCourse(cour0);
        stu1.removeCourse(cour2);
        stu1.removeCourse(cour1);
        
        File f=new File("E:\\java_prectise\\hello\\src\\output.txt");
        FileOutputStream fos1=new FileOutputStream(f);
        OutputStreamWriter dos1=new OutputStreamWriter(fos1);
        String yy = ("选课信息如下：\n"+"学生信息：\n"+stu0.toString()+stu1.toString()+"\n"+stu2.toString()+"\n"+stu3.toString()+
        		"\n"+"教师信息：\n"+tea0.toString()+tea1.toString()+tea2.toString()+"\n课程信息：\n"+cour0.toString1()+cour1.toString1()+cour2.toString1());
       dos1.write(yy);
       dos1.close();
       
       File file1 = new File("E:\\java_prectise\\hello\\src\\Stuoutput.out");
       ObjectOutputStream oout1 = new ObjectOutputStream(new FileOutputStream(file1));
       oout1.writeObject(stu0.toString());
       oout1.writeObject(stu1.toString());
       oout1.writeObject(stu2.toString());
       oout1.writeObject(stu3.toString());
       File file2 = new File("E:\\java_prectise\\hello\\src\\Stuoutput'.out");
       ObjectOutputStream oout2 = new ObjectOutputStream(new FileOutputStream(file2));
       oout2.writeObject(tea0.toString());
       oout2.writeObject(tea1.toString());
       oout2.writeObject(tea2.toString());
       File file3 = new File("E:\\java_prectise\\hello\\src\\Stuoutput'.out");
       ObjectOutputStream oout3 = new ObjectOutputStream(new FileOutputStream(file3));
       oout3.writeObject(cour0.toString1());
       oout3.writeObject(cour1.toString1());
       oout3.writeObject(cour2.toString1());
       oout1.close();
       oout2.close();
       oout3.close();
       ObjectInputStream oinStu = new ObjectInputStream(new FileInputStream("E:\\java_prectise\\hello\\src\\Stuoutput'.out"));
       Object Student0 = oinStu.readObject();
       Object Student1 = oinStu.readObject();
       Object Student2 = oinStu.readObject();

       oinStu.close();
       System.out.println("退课操作之前："+Student0);
       System.out.println("退课操作之前："+Student1);
       System.out.println("退课操作之前："+Student2);
       
       ObjectInputStream oinTea = new ObjectInputStream(new FileInputStream("E:\\java_prectise\\hello\\src\\Stuoutput'.out")); 
       Object newTeacher0 = oinTea.readObject(); 
       Object newTeacher1 = oinTea.readObject(); 
       Object newTeacher2 = oinTea.readObject(); 
       oinTea.close(); 
       System.out.println(newTeacher0);
       System.out.println(newTeacher1); 
       System.out.println(newTeacher2);
       
       ObjectInputStream oinCour = new ObjectInputStream(new FileInputStream("E:\\java_prectise\\hello\\src\\Stuoutput'.out")); 
       Object newCourse0 = oinCour.readObject();
       Object newCourse1 = oinCour.readObject();
       Object newCourse2 = oinCour.readObject();
       oinCour.close();
      
       System.out.println("退课操作之前"+newCourse0);
       System.out.println("退课操作之前"+newCourse1);
       System.out.println("退课操作之前"+newCourse2);
      
       
       File file01 = new File("E:\\java_prectise\\hello\\src\\Stuoutput'.out");
       ObjectOutputStream oout01 = new ObjectOutputStream(new FileOutputStream(file01));
       stu0.removeCourse(cour0);
       Object Student100=String.valueOf(stu0.toString());
       stu1.removeCourse(cour2);
       stu1.removeCourse(cour1);
       Object Student101=String.valueOf(stu1.toString());
       oout01.writeObject(Student100.toString());
       oout01.writeObject(Student101.toString());
       Object Student102=String.valueOf(stu2.toString());
       System.out.println("退课操作之后："+Student100);
       System.out.println("退课操作之后："+Student101);
       System.out.println("退课操作之后："+Student102); 
       
       File file03 = new File("E:\\java_prectise\\hello\\src\\Couroutput'.out");
       ObjectOutputStream oout03 = new ObjectOutputStream(new FileOutputStream(file03));
       stu0.removeCourse(cour0);
       stu1.removeCourse(cour1);
       stu1.removeCourse(cour2);
       Object Course100=String.valueOf(cour0.toString1());
       Object Course101=String.valueOf(cour1.toString1());
       Object Course102=String.valueOf(cour2.toString1());
       oout03.writeObject(Course100.toString());
       oout03.writeObject(Course101.toString());
       oout03.writeObject(Course102.toString());
       System.out.println("退课操作之后"+Course100);
       System.out.println("退课操作之后"+Course101);
       System.out.println("退课操作之后"+Course102);

	}
}


